package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Override
    public void add(BusinessTrackVo businessTrackVo) {
        /*tbBusinessTrackRecordMapper.add(businessTrackVo);
        businessTrackVo.setCreateBy(SecurityUtils.getUsername());
        Date date = new Date();
        businessTrackVo.setCreateTime(date);*/
        //更新商机数据
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusiness.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbBusinessMapper.updateTbBusiness(tbBusiness);
//添加商机跟进记录
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(businessTrackVo, tbBusinessTrackRecord);
//调用工具类获取用户名
        String username = SecurityUtils.getUsername();
//获取当前时间
        Date createTime = new Date(System.currentTimeMillis());
        tbBusinessTrackRecord.setCreateBy(username);
        tbBusinessTrackRecord.setCreateTime(createTime);
        tbBusinessTrackRecordMapper.add(tbBusinessTrackRecord);
    }

    @Override
    public List<BusinessTrackVo> selectRecordList(Long id) {
        return tbBusinessTrackRecordMapper.selectRecordList(id);
    }
}
